package com.ddy.test.exam;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExamDistribution {

    public static void main(String[] args) {

        List<String> exams = new ArrayList<>();
        exams.add("a");
        exams.add("b");
        exams.add("c");
        exams.add("d");
        exams.add("e");
        exams.add("f");

        List<String> teams = new ArrayList<>();
        teams.add("1");
        teams.add("2");
        teams.add("3");
        teams.add("4");
        teams.add("5");
        teams.add("6");



        Map<String,List<String>> exam_dist = new HashMap<>();
        int exam_times = 4;
        for(int i=0;i<exam_times;i++){

            Map<String, String> result = new HashMap<>();


            for(int j=0;j<exams.size();j++){
                String exam = exams.get(j);
                int random = getRandom(teams.size());
                String team = teams.get(random);
                System.out.print(exam+" -> "+team + " ");
                if(result.containsValue(team)){//本轮安排
                    System.out.println("cur has " + team + ",pass.");
                    j--;
                    continue;
                }

                List<String> team_history_list = exam_dist.get(exam);
                if(team_history_list == null){
                    team_history_list = new ArrayList<>();
                    exam_dist.put(exam, team_history_list);
                }

                if(team_history_list.contains(team)){
                    System.out.println("history has " + team + ",pass.");
                    j--;
                    continue;
                }
                team_history_list.add(team);
                result.put(exam, team);

            }
            System.out.println();
            System.out.println("============================================>> "+result);


        }

    }

    public static int getRandom(int size){
        return (int)(Math.random() * size);
    }
}
